﻿using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command;

namespace U.B.WriteApi.CommandHander
{
    public class DeluserroleCommandHander : IRequestHandler<DeluserroleCommand, ApiResult<object>>
    {
        public readonly IRepistory<UserRole> urRepository;

        public DeluserroleCommandHander(IRepistory<UserRole> urRepository)
        {
            this.urRepository = urRepository;
        }
        public Task<ApiResult<object>> Handle(DeluserroleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            var result = urRepository.GetAll().Where(x => x.UserRoleId == request.UserRoleId).FirstOrDefault();
            urRepository.Delete(result);
            apiResult.code = Renum.删除成功;
            apiResult.Message = Renum.删除成功.ToString();
            return Task.FromResult(apiResult);

        }
    }
}
